package com.xone.xapp;

import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.Toast;

public abstract class LogoutDataTask extends AsyncTask<String, Integer, JSONObject> {
	protected Context context;
	public LogoutDataTask(Context context) {
		this.context = context;
	}
	@Override
	protected JSONObject doInBackground(String... params) {
		if (isCancelled()) {
			return null;
		}
		return HttpUtils.httpGet(Constants.APP_URL + "/login/logoutjson.html", null,
				new HttpUtils.onGetSuccessListener<JSONObject>() {
					@Override
					public JSONObject onSuccess(int status, String result) {
						if (HttpUtils.SC_OK == status) {
							return JSONUtils.getJSONObjectFromString(result);//JSONUtils.getJSONListFromIdentifyString(result, "list");
						}
						return null;
					}
				});
	}
	
	@Override
	protected void onPostExecute(JSONObject result) {
		super.onPostExecute(result);
		onFinish(result);
		if (isCancelled()) {
			return;
		}
		if (null == result) {
			Toast.makeText(context, "操作失败", Toast.LENGTH_SHORT).show();
			return;
		}
		Toast.makeText(context, "操作成功", Toast.LENGTH_SHORT).show();
		ShareUtils.setPrefs(ShareUtils.PASSWROR, null, context);
		UserInfo.userMap.clear();
		UserInfo.alevelUser = false;
		UserInfo.blevelUser = false;
		UserInfo.clevelUser = false;
		UserInfo.login = false;
		Intent i = new Intent(context, LoginActivity.class);
		context.startActivity(i);
	}
	
	public abstract void onFinish(JSONObject resutl);
}
